package view.frontend.order;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import model.GraveYard;
import view.generaldesign.DesignLayout;

/**
 *
 * @author Sonny Sandberg
 */
public class OrderGraveYardListPanel extends JPanel
{
    private OrderGraveYard orderGraveYard;
    
    public OrderGraveYardListPanel(final OrderGraveYard view, final GraveYard graveYard)
    {
        orderGraveYard = view;
        
        setLayout(null);
        setSize(new Dimension(220, 130));
        setBorder(DesignLayout.T_FIELD_RED);
        
        JLabel lblName = new JLabel(graveYard.getName());
        lblName.setBounds(10, 5, 220, 18);
        lblName.setFont(DesignLayout.STANDARD.deriveFont(11f));
        
        JLabel lblStreet = new JLabel(graveYard.getAddress().getStreet());
        lblStreet.setBounds(10, 25, 220, 18);
        lblStreet.setFont(DesignLayout.STANDARD.deriveFont(11f));
        
        JLabel lblZipCity = new JLabel(graveYard.getAddress().getZipCode().toString());
        lblZipCity.setBounds(10, 45, 220, 18);
        lblZipCity.setFont(DesignLayout.STANDARD.deriveFont(11f));
        
        JButton btnAddToOrder = new JButton("vælg");
        btnAddToOrder.setFont(DesignLayout.STANDARD.deriveFont(11f));
        btnAddToOrder.setBorder(DesignLayout.T_FIELD_RED);
        btnAddToOrder.setBackground(Color.lightGray);
        btnAddToOrder.setPreferredSize(new Dimension(40, 30));
        btnAddToOrder.addActionListener(new ActionListener() 
        {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                orderGraveYard.getOrder().getOrderObject().getTombStone().setGraveYard(graveYard);
                orderGraveYard.gettFieldGraveYard().setText(graveYard.getName());
                orderGraveYard.getExistingGraveYardsPanel().setVisible(false);                
            }
        });
        
        JPanel panelButtons = new JPanel();
        panelButtons.setBounds(4, 70, 210, 35);
        panelButtons.add(btnAddToOrder);
        
        add(lblName);
        add(lblStreet);
        add(lblZipCity);
        add(panelButtons);
    }
}